/**
 * @param {number[]} nums
 * @return {number}
 */

var longestConsecutive = function(nums) {
    let max = 0;
    let map = new Map()
    for(let i = 0; i < nums.length; i++){
        if (!map.has(nums[i])) {
            let left = map.get(nums[i] - 1) || 0
            let right = map.get(nums[i] + 1) || 0
            let cur = left + right + 1
            map.set(nums[i], cur)
            max = Math.max(max, cur)
            map.set(nums[i] - left, cur)
            map.set(nums[i] + right, cur)
        }
    }
    return max;
};